package m1;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

/**
 * @author 郭鲁政
 */
public class Consumer {
    public static void main(String[] args) throws MQClientException {
        DefaultMQPushConsumer c = new DefaultMQPushConsumer("prod-group");
        c.setNamesrvAddr("192.168.64.141:9876");
    c.subscribe("Topic", "TagA || TagB || TagC");
    c.setMessageListener(new MessageListenerConcurrently() {
        @Override
        public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
            for (MessageExt messageExt : list) {
                String s = new String(messageExt.getBody());
                System.out.println("收到:"+s);
            }
            return ConsumeConcurrentlyStatus.RECONSUME_LATER;//稍后重新消费
     //   return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        }
    });
    c.start();
        System.out.println("开始消费数据");
    }
}
